//
//  SINAServicePariseViewController.m
//  sinashebao
//
//  Created by  androidlongs on 2017/12/21.
//  Copyright © 2017年  androidlongs. All rights reserved.
//

#import "SINAServicePariseViewController.h"
#import "XHStarRateView.h"
#import "SINACircularBeadUtils.h"
#import "SINAServicePariseModel.h"
@interface SINAServicePariseViewController ()


@property (weak, nonatomic) IBOutlet UIScrollView *mainScrollView;


//兼职满意度
@property (weak, nonatomic) IBOutlet UIView *partTimePariseView;
//委托满意度
@property (weak, nonatomic) IBOutlet UIView *servicePariseView;
//头像
@property (weak, nonatomic) IBOutlet UIImageView *titleImageView;
//实名
@property (weak, nonatomic) IBOutlet UILabel *realNameLabel;


//委托总数
@property (weak, nonatomic) IBOutlet UILabel *serviceTotalLabel;

//委托完成
@property (weak, nonatomic) IBOutlet UILabel *serviceFinishLabel;

//兼职总数
@property (weak, nonatomic) IBOutlet UILabel *partTimeTotalLabel;
//兼职完成
@property (weak, nonatomic) IBOutlet UILabel *partTimeFinishLabel;

//总单数
@property (weak, nonatomic) IBOutlet UILabel *totalOrderLabel;
//完成度
@property (weak, nonatomic) IBOutlet UILabel *orderFinishLabel;

@property(strong,nonatomic) SINAServicePariseModel *model;
@end

@implementation SINAServicePariseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self configNavigationItem];
    //[self initViewFunction];
    
    SINAUserModel *userModel = [[SINACommonUserHelper share] getUserModel];
    if (userModel!=nil) {
        //设置昵称
        NSString *userNikName = userModel.userRealName;
        if (userNikName==nil||[userNikName isEqualToString:@""]) {
            userNikName = @"***";
        }
        self.realNameLabel.text=userNikName;
      
        //头像
        NSString *headerImageUrl = userModel.userTitleImageUrl;
        if (headerImageUrl!=nil&&headerImageUrl.length>1) {
            NSURL *imageUrl =[NSURL URLWithString:headerImageUrl];
            [self.titleImageView sd_setImageWithURL:imageUrl placeholderImage:[UIImage imageNamed:@"默认头像"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                DLog(@"加载头像完成");
            }];
        }
        
        
    }
    // Do any additional setup after loading the view from its nib.
}

-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBarHidden = NO;
    [self loadinServicePariseDataFunction];
}

-(void)initViewFunction{
    
    self.mainScrollView.frame = CGRectMake(0, 0, mainW, mainH);
    self.mainScrollView.contentSize=CGSizeMake(mainW, mainH);
    self.mainScrollView.showsVerticalScrollIndicator=NO;
    self.mainScrollView.showsHorizontalScrollIndicator=NO;
    self.titleImageView.frame=CGRectMake(mainW/2-73/2, 30, 73, 73);
    
    
     [SINACircularBeadUtils makeCircularView:self.titleImageView];
    
    CGFloat paddingLeft=0;
    CGFloat paddingTop=5;
    CGFloat rateViewWidth=140;
    CGFloat rateViewHeight=18;
    
    //接
    XHStarRateView *receiveTasksRateView = [[XHStarRateView alloc] initWithFrame:CGRectMake(paddingLeft, paddingTop, rateViewWidth, rateViewHeight) numberOfStars:5 selectNumberStars:self.model.parttimeevaluatecnt rateStyle:HalfStar isAnination:YES finish:^(CGFloat currentScore) {
        DLog(@"4----  %f",currentScore);
    }];
    
    receiveTasksRateView.isTouch=NO;
    [self.partTimePariseView removeAllSubviews];
    [self.partTimePariseView addSubview:receiveTasksRateView];
    
    
    //完成满意度评分
    XHStarRateView *completeSatisfactionRateView = [[XHStarRateView alloc] initWithFrame:CGRectMake(paddingLeft, paddingTop, rateViewWidth, rateViewHeight) numberOfStars:5 selectNumberStars:self.model.serveevaluatecnt rateStyle:HalfStar isAnination:YES finish:^(CGFloat currentScore) {
        DLog(@"4----  %f",currentScore);
    }];
     [self.servicePariseView removeAllSubviews];
    [self.servicePariseView addSubview: completeSatisfactionRateView];
    
    
    //总单数
    NSInteger totalOrder = self.model.servecnt+self.model.parttimecnt;
    //完成单数
    NSInteger finishOrder =self.model.servefinishcnt+self.model.parttimefinishcnt;
    
    //比例
    NSInteger flagNum =(int)( finishOrder *1.0f/totalOrder * 100);
    
    self.totalOrderLabel.text=[NSString stringWithFormat:@"共计：%ld单",(long)totalOrder];
    
    self.orderFinishLabel.text=[NSString stringWithFormat:@"完成度：%ld %%",(long)flagNum];
    
    self.serviceTotalLabel.text=[NSString stringWithFormat:@"委托：%ld单",(long)self.model.servecnt];
    self.serviceFinishLabel.text=[NSString stringWithFormat:@"完成：%ld单",(long)self.model.servefinishcnt];
    
    self.partTimeTotalLabel.text=[NSString stringWithFormat:@"接单：%ld单",(long)self.model.parttimecnt];
    self.partTimeFinishLabel.text=[NSString stringWithFormat:@"完成：%ld单",(long)self.model.parttimefinishcnt];
}
-(void)configNavigationItem{
    self.navigationController.navigationBarHidden = NO;
    self.navigationItem.title=@"服务评价";
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0/255 green:198.0/255 blue:174.0/255 alpha:0.8f];
    self.navigationController.navigationBar.translucent = NO;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],
                                                                      NSForegroundColorAttributeName:[UIColor whiteColor]}];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void) loadinServicePariseDataFunction{

    [self startLoading];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    [dict setObject:[NSString stringWithFormat:@"%@",[[SINACommonUserHelper share] getUserModel].userUid] forKey:@"useruuid"];
    WeakSelf;
    [CXAFNHttpRequestUtils httpGetRequest:[NSString stringWithFormat:@"%@%@",baseUrl,stuGetServicePariseUrl] withParamters:dict success:^(id responseData) {
        NSString *code = responseData[@"code"];
        [weakSelf stopLoading];
        if ([code isEqualToString:@"1000"]) {
            NSDictionary *resultDictionary = responseData[@"content"];
            SINAServicePariseModel *model = [[SINAServicePariseModel alloc]initWithDict:resultDictionary];
            weakSelf.model = model;
            [weakSelf updateDataFunction ];
        }else{
            NSString *message =responseData[@"message"];
            WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:message sureBtn:@"确定"
                                                                 cancleBtn:nil];
            [alertView showXLAlertView];
           
        }
    } failure:^(NSError *error, NSInteger errCode) {
        [weakSelf stopLoading];
        DLog(@"加载 失败  %@ ",error.debugDescription);
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"加载数据失败" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
    }];
}

//更新数据
-(void) updateDataFunction{
    [self initViewFunction];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
